function updata()
{
  document.getElementById('light').style.display = 'block';
  document.getElementById('fade').style.display = 'block';
  var s = $('#table').bootstrapTable('getSelections');
  //alert(s.length);
  document.getElementById('name').value = s[0].name;
  document.getElementById('number').value = s[0].number;
  document.getElementById('price').value = s[0].price;
  $('#put').click(function ()
  {
    var s = $('#table').bootstrapTable('getSelections');
    var id = s[0].id;
    var name = document.getElementById('name').value;
    var number = document.getElementById('number').value;
    var price = document.getElementById('price').value;
    $.ajax({
      type: 'POST',
      url: 'DispatchAction?method=updataDrug',
      data: 'id=' + id + '&name=' + name + '&number=' + number + '&price=' + price,
      success: function (msg) {
        if (msg == 'true')
        {
          alert('修改成功');
          document.getElementById('light').style.display = 'none';
          document.getElementById('fade').style.display = 'none';
          $('#table').bootstrapTable('refresh');
          return true;
        } 
        else {
          alert('修改failuer');
          return false;
        }
      },
    });
  });
}
function insert()
{
  var name = document.getElementById('name2').value;
  var number = document.getElementById('number2').value;
  var price = document.getElementById('price2').value;
  $.ajax({
    type: 'POST',
    url: 'DispatchAction?method=insertDrug',
    data: 'name=' + name + '&number=' + number + '&price=' + price,
    success: function (msg) {
      if (msg == 'true')
      {
        alert('添加成功');
        document.getElementById('light2').style.display = 'none';
        document.getElementById('fade').style.display = 'none';
        $('#table').bootstrapTable('refresh');
        return true;
      } 
      else {
        alert('添加failuer');
        return false;
      }
    },
  });
}
function delect()
{
  var s = $('#table').bootstrapTable('getSelections');
  var last = JSON.stringify(s);
  $.ajax({
    type: 'POST',
    url: 'DispatchAction?method=delectDrug',
    data: 'json=' + last,
    success: function (msg) {
      if (msg) {
        alert('删除成功');
        $('#table').bootstrapTable('refresh');
      } 
      else {
        alert('删除失败!');
      }
    },
    // datatype:JSON
  });
}
